<template>
	<view class="body">
		<!-- 操作菜单 -->
		<paper-left-popup :show="show" @hide="hidepopup" @addfriend="addfriend" @clear="clear"></paper-left-popup>
		
		<!-- 小纸条列表 -->
		<block v-for="(item, index) in list" :key="index">
			<paper-list :item="item" :index="index"></paper-list>
		</block>
		
		<!-- 上拉加载 -->
		<load-more :loadtext="loadtext"></load-more>
	</view>
</template>

<script>
import paperList from '../../components/paper/paper-list.vue';//小纸条列表
import loadMore from '../../components/common/load-more.vue'; //上拉加载
import paperLeftPopup from '../../components/paper/paper-left-popup.vue'//操作菜单
export default {
	components: {
		paperList,
		loadMore,
		paperLeftPopup
	},
	data() {
		return {
			show:false,
			loadtext:"上拉加载更多",
			list: [
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:21',
					data: '我是信息',
					noreadnum: 5
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:21',
					data: '我是信息',
					noreadnum: 0
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:21',
					data: '我是信息',
					noreadnum: 0
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:21',
					data: '我是信息',
					noreadnum: 11
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:21',
					data: '我是信息',
					noreadnum: 5
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:21',
					data: '我是信息',
					noreadnum: 5
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:21',
					data: '我是信息',
					noreadnum: 0
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:21',
					data: '我是信息',
					noreadnum: 0
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:21',
					data: '我是信息',
					noreadnum: 11
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:21',
					data: '我是信息',
					noreadnum: 5
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:21',
					data: '我是信息',
					noreadnum: 5
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:21',
					data: '我是信息',
					noreadnum: 0
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:21',
					data: '我是信息',
					noreadnum: 0
				}
			]
		};
	},
	//监听下拉刷新
	onPullDownRefresh() {
		this.getdata()
	},
	onReachBottom() {
		this.loadmore()
	},
	// 监听导航按钮点击事件
	onNavigationBarButtonTap(e) {
		// console.log(JSON.stringify(e))
		switch (e.index){
			case 0:
			console.log("点击了左边按钮");
			this.hidepopup()
				break;
			case 1:
			console.log("点击了右边按钮")
			this.showpopup()
				break;
		}
	},
	methods: {
		// 操作菜单
		addfriend(){
			console.log("加糗友");
			this.hidepopup()
		},
		clear(){
			console.log("清除缓存");
			this.hidepopup()
		},
		hidepopup(){
			this.show = false;
		},
		showpopup(){
			this.show = true;
		},
		// 获取数据
		getdata(){
			setTimeout(()=>{
				// 服务器获取数据
				let arr = [
					{
						userpic: '../../static/demo/userpic/1.jpg',
						username: '1111',
						time: '10:21',
						data: '我是信息',
						noreadnum: 5
					},
					{
						userpic: '../../static/demo/userpic/12.jpg',
						username: '2222',
						time: '10:21',
						data: '我是信息',
						noreadnum: 0
					},
					{
						userpic: '../../static/demo/userpic/3.jpg',
						username: '3333',
						time: '10:21',
						data: '我是信息',
						noreadnum: 0
					},
					{
						userpic: '../../static/demo/userpic/4.jpg',
						username: '4444',
						time: '10:21',
						data: '我是信息',
						noreadnum: 9
					},
					{
						userpic: '../../static/demo/userpic/5.jpg',
						username: '5555',
						time: '10:21',
						data: '我是信息',
						noreadnum: 0
					}
				];
				// 赋值
				this.list = arr;
				// 关闭下拉刷新
				uni.stopPullDownRefresh();
			},2000)
			
		},
		// 上拉加载
		loadmore(){
			setTimeout(()=>{
				if(this.loadtext != "上拉加载更多"){
					return;
				}
				this.loadtext = "加载中...";
				let obj={
						userpic: '../../static/demo/userpic/11.jpg',
						username: '昵称',
						time: '10:21',
						data: '我是信息',
						noreadnum: 0
					};
					this.list.push(obj);
					this.loadtext = "上拉加载更多";
			},2000)
			
		}
		
		
		
	}
};
</script>

<style>
	.body{
		padding:0 20upx;
	}
	
</style>
